#include <p32xxxx.h>
#include <plib.h>
#include "Thread.h"

Thread::Thread() { }

Thread::~Thread() { }

/*! \brief Pauses program execution for the specified number of milliseconds.
 *
 * Pauses program execution for the specified number of milliseconds.
 * @param duration
 */
void Thread::Sleep(UINT32 duration)
{
	// NOTE: Core Timer Ticks every two FOCC's
	WriteCoreTimer(0);
	while (ReadCoreTimer() < ((float)duration / 1000.0f * (FOSC/2)))
	{
		Nop();
	}
}

/*! \brief Pauses program execution for the specified number of microseconds.
 *
 * Pauses program execution for the specified number of microseconds.
 * @param duration
 */
void Thread::SleepUs(UINT32 duration)
{
	// NOTE: Core Timer Ticks every two instructions
	WriteCoreTimer(0);
	while (ReadCoreTimer() < ((float)duration / 1000000.0f * (FOSC/2)))
	{
		Nop();
	}
}
